package com.github.limit.param;

import com.github.limit.util.IpUtils;
import com.github.limit.util.RequestUtils;

import javax.servlet.http.HttpServletRequest;

/**
 * @author: wangdejun
 * @create: 2019-10-21 13:49
 **/
public class InterceptorParam implements IParam {

    /**
     * 获取token，可以自定义参数名
     *
     * @param name
     * @return
     */
    @Override
    public String getToken(String name) {
        HttpServletRequest request = RequestUtils.getRequest();
        return request.getHeader(name);
    }

    /**
     * 获取sessionId
     *
     * @return
     */
    @Override
    public String getSessionId() {
        HttpServletRequest request = RequestUtils.getRequest();
        return request.getSession().getId();
    }

    /**
     * 获取ip
     *
     * @return
     */
    @Override
    public String getIp() {
        HttpServletRequest request = RequestUtils.getRequest();
        return IpUtils.getIpAddr(request);
    }
}
